package com.eaoa.query.pub;

import org.apache.commons.lang.StringUtils;

import com.eaoa.base.EABaseQuery;
import com.eaoa.vo.pub.PubDocument;

public class PubDocumentQuery extends EABaseQuery {

	public PubDocumentQuery() {
		super(PubDocument.class);
	}


	public void setDocumentno(Long val) {
		setEQCondition("documentno", val);
	}

	public void setCreatedbyname(String val) {
		setLIKECondition("createdbyname", val);
	}

	public void setCreatedby(Long val) {
		setEQCondition("createdby", val);
	}

	public void setCreatedate(String val1, String val2) {
		buildDateCondition("createdate", val1, val2);
	}
	
	public void setModuleno(String val) {
		setEQCondition("pubModule.moduleno", val);
	}
	
	public void setTopModule(String val) {
		if(StringUtils.isNotBlank(val)){
			setLIKECondition("pubModule.modulepath", ","+val+",");
		}
	}

	public void setTitle(String val) {
		setLIKECondition("title", val);
	}
	
	public void setDocumenttype(String val) {
		setEQCondition("documenttype", val);
	}
	
	public void setOrderByNoDesc() {
		setOrdersql(" ORDER BY this.documentno DESC");
	}
	
	public void fetchModule() {
		setLeftJoinFetchs(" left join fetch this.pubModule pubModule ");
	}

	public static PubDocument loadByNo(Long documentno) {
		PubDocumentQuery query = new PubDocumentQuery();
		query.setDocumentno(documentno);
		query.fetchModule();
		query.setOrderByNoDesc();
		query.execute();

		if (query.getResults().size() != 1)
			return null;

		return (PubDocument) query.getResults().get(0);
	}

}
